<script type="text/javascript">
$(document).ready(function(){
	$('.add_prod').animate({opacity:0.4},'fast');
	$('.ctn_menu ').each(function(index){
		$(this).bind({
			
			mouseenter:function(){
				$i= $('.add_prod');
				$(this).find($i).animate({opacity:1},'fast');
				$(this).css('background','#fff');
				
							
				},

			mouseleave:function(){
				$(this).find('.add_prod').animate({opacity:0.4},'fast');
				$(this).css('background','#e1e1e1');
				}

		});
		})

})
//button less and more
function less(id,name)
{	
	if(name && name == 'Table de riz'){
		$val_1 = $('#item_'+id).val();
		if($val_1 !=4){
		$('#item_'+id).val($val_1-1);
		}
	}else{
	$val_1 = $('#item_'+id).val();
	if($val_1 >=1){
	$('#item_'+id).val($val_1-1);
	}
	}
}

function more(id)
{
	$val_1 = $('#item_'+id).val();	
	$new_val = $val_1*1 +1 ;
	$('#item_'+id).val($new_val);

}
function add_cart(id){

	if($('#item_'+id).val()==0){
		alert('Veuillez vous choisir la quantité (QTY).');
		}else{
			
			jQuery('form[name=addproduct'+id+']').submit();
			
			}
}
function validation(id){
	var valid = true;
	if($('#rightbar select').length){
		$select = $('#rightbar select');
		$select.each(function(i,dom){
					if($(this).val() == ''){
							alert('Veuillez-vous choisi votre '+$(this).attr('id'));
							return valid = false;		
					}
					});

	if(valid == true){			
		add_cart(id);
	}
		}
}
</script>

<div id="container">
	<div id="sidebar">
	<div class="logo"><a href="<?=site_url()?>"><img src="<?=base_url()?>resources/imgs/logo.png" alt="" width="200"></a><p class="sub-title">Traiteur Chinois</p></div>
		<h3>
			Panier
			<?=$this->cart->total_items()?>
			|
			<?=number_format($this->cart->total(),2,'.','')?>
			€
		</h3>
		
		<?php $i = 1; ?>
		<?php if(!$this->cart->contents()){?>
		<p>
			Panier Vide
		</p>
		<?php }?>
		<form action="<?=site_url('cart/cart_update')?>?url=<?=current_url()?>" name="update_cart" enctype="multipart/form-data" method="post">
		<?php foreach ($this->cart->contents() as $items): ?>
		<div class="order_item">
			<span class="product_item"> 
			<?php echo form_hidden($i.'[rowid]', $items['rowid']); ?><?=$items['product_num']?>.<?=nbs(0)?> <?php echo $items['name']; ?>
			</span>
			<span class="qty"><?php if($items['options_price'] !=NULL && $items['options_price'] != 0){?> <?=number_format($items['price']+$items['options_price'],2,'.','')?> € <?php }else{?> <?=number_format($items['price'],2,'.','')?> € <?php }?>x <select name="<?=$i.'[qty]'?>" onchange="document.update_cart.submit();">
 	<?php if($items['name']=='Table de riz'){$q=4; echo '<option value="0">0</option>';}else{$q=0;} for($q;$q<20;$q++){?> 
 	<option value="<?=$q?>" id="<?=$i.'[qty]'?>"<?php if($items['qty']==$q){echo "selected='selected'";}?> ><?=$q?></option>
 	<?php }?>
 	</select>
 	</span>
			<br><span class="option"><?php if($this->cart->has_options($items['rowid'])==TRUE):?><label><small>OPTIONs:	</small></label><br><?php foreach ($this->cart->product_options($items['rowid']) as $option): ?><?=nbs(0)?>

					<small><?php echo $option['option_name']; ?> <?php if( $option['price'] !=NULL ){ echo ': '.$option['price'].' €';} ?></small><?=nbs(1)?>

					<?php endforeach; ?>		
					<?php endif; ?></span>
			<div class="clear"></div>

		</div>
		<?php $i++; ?>
		<?php endforeach; ?>
		</form>
		<div class="clear"></div>
		<br><br>
		<input class="btn_panier" type="button" value="MON PANIER" onclick="document.location.href='<?=site_url('cart')?>'">
		<hr>
		<a href="<?=site_url('account')?>">Voir Dernière Commande <img style="vertical-align:bottom;" src="<?=base_url()?>/resources/imgs/find.png" height="18"/></a>
		
		<?=br(2)?>
		<h3>Sauce supplémentaire</h3>
		
			<?php foreach ($sauces as $s):?>
		<div class="sauce_item">
		
		<small style="text-align:right;"><form action="<?=site_url('cart/insert')?>" method="post">
		<?=$s->product_name?> <?=$s->product_price?>€ X
		<select name="qty">
		<?php for($k=1;$k<5;$k++){?>
		<option value="<?=$k?>"><?=$k?></option>
		<?php }?>
		</select>
		<input type="hidden" name="url" value="<?=current_url()?>">
		<input type="hidden" name="id" value="<?=$s->id?>">
		<input type="hidden" name="price" value="<?=$s->product_price?>">
		<input type="hidden" name="name" value="<?=$s->product_name?>">
		<input type="hidden" name="product_num" value="<?=$s->product_num?>">
		<input type="submit" value="ajouter" class="button">
		</form></small>
		
		</div>
		<?php endforeach;?>
		<?php if($this->discount || $this->discount_delivery){?>
		<h3>Promo!</h3>
		<?php if($this->discount){?>
	<div class="promo">
	A partir du <?=date('d M. Y',strtotime($this->discount[0]->discount_start))?> jusqu'au <?=date('d M. Y',strtotime($this->discount[0]->discount_end))?>, Une Réduction de <?=$this->discount[0]->discount_val*100?>% pour toutes les commandes paiement par espèces !!!
	</div>
	<?php }?>
	<?php if($this->discount_delivery){?>
	<div class="promo">
	A partir du <?=date('d M. Y',strtotime($this->discount_delivery[0]->discount_start))?> jusqu'au <?=date('d M. Y',strtotime($this->discount_delivery[0]->discount_end))?>,  Pour les commandes de livraison, Une Réduction de <?=$this->discount_delivery[0]->discount_val*100?>% 
	pour les communes: <br>
	<?php foreach ($this->discount_delivery[0]->community as $c):?>
	<?=$c->code?> <?=$c->name?> / 
	<?php endforeach;?>
	!!!</div>
	<?php }?>
	<?php }?>
	</div>
	<div id="rightbar">
	<?php if($product){?>
<?php foreach ($product as $p):?>
	<?php if($this->uri->segment(2)==4){?>


<?php if($p->product_name == 'Table de riz' || $p->product_num == '1002'){?>

	<h1>
	<?=$p->product_name?>
	</h1>
	<?=$p->capture?>

	<div class="item_form">
		<form action="<?=site_url('cart/insert')?>" method="post" name="addproduct<?=$p->id?>">
			<input type="button" class="moins format_<?=$p->id?>_less" value="-" onclick="less(<?=$p->id?>,'<?=$p->product_name?>')">
			<input type="text" name="qty" class="qty" id="item_<?=$p->id?>" value="4" style="width: 20px; text-align: center;" />
			<input type="button" class="plus format_<?=$p->id?>_more" value="+" onclick="more(<?=$p->id?>)"> 
			<input type="hidden" class="id_<?=$p->id?>" name="id" value="<?=$p->id?>"> 
			<input type="hidden" class="price_<?=$p->id?>" name="price" value="<?=$p->product_price?>"> 
			<input type="hidden" class="name_<?=$p->id?>" name="name" value="<?=$p->product_name?>">
			<input type="hidden" class="num_<?=$p->id?>" name="product_num" value="<?=$p->product_num?>"> 
			<input type="hidden" name="url" value="<?=current_url()?>">
			<input type="button" value="ajouter" onclick="add_cart(<?=$p->id?>)">
		</form>
	</div>
	<hr>
		<?php foreach ($p->attribute_group as $group):?>
				<div style="padding: 20px;">	
				<h2><?=$group->attribute_group_name?></h2>	
				
					<?php foreach ($group->attribute_product as $product_attribute):?>
					<?=$product_attribute->attribute_name?><br><br>
					<?php endforeach;?>
				
				</div>
				<?php endforeach;?>
	<hr>
	
	<?php }else{?>

	<h1>
	<?=$p->product_name?>
	</h1>
	<?=$p->capture?>

	<div class="item_form">
		<form action="<?=site_url('cart/insert')?>" method="post" name="addproduct<?=$p->id?>">
			<input type="button" class="moins format_<?=$p->id?>_less" value="-" onclick="less(<?=$p->id?>)">
			<input type="text" name="qty" class="qty" id="item_<?=$p->id?>" value="0" style="width: 20px; text-align: center;" />
			<input type="button" class="plus format_<?=$p->id?>_more" value="+" onclick="more(<?=$p->id?>)"> 
			<input type="hidden" class="id_<?=$p->id?>" name="id" value="<?=$p->id?>"> 
			<input type="hidden" class="price_<?=$p->id?>" name="price" value="<?=$p->product_price?>"> 
			<input type="hidden" class="name_<?=$p->id?>" name="name" value="<?=$p->product_name?>">
			<input type="hidden" class="num_<?=$p->id?>" name="product_num" value="<?=$p->product_num?>"> 
			<input type="hidden" name="url" value="<?=current_url()?>">
			<input type="button" value="ajouter" onclick="validation(<?=$p->id?>)">
		
	</div>

	<hr>
		<?php foreach ($p->attribute_group as $group):?>
				<div style="padding: 20px;">	
				<h2><?=$group->attribute_group_name?></h2>	
					<?php if(count($group->attribute_product)>1){?>
				 <div class="styled-select">
				<select name="option[]" class="options_class" id="<?=$group->attribute_group_name?>">
						<option value="">
							Choisissez votre
							<?=$group->attribute_group_name?>...
						</option>
						<?php foreach ($group->attribute_product as $product_attribute):?>
						<option value="<?=$product_attribute->id?>">
						<?=$product_attribute->attribute_name?>
						<?php if($product_attribute->attribute_price !=null){?><?=number_format($product_attribute->attribute_price,'2','.','')?> €<?php }?>
							
						</option>
						<?php endforeach;?>
				</select> 
				</div>
				<?php }else{?>
					<?php foreach ($group->attribute_product as $product_attribute):?>
					<?=$product_attribute->attribute_name?>
					<?php endforeach;?>
				<?php }?>
				</div>
				<?php endforeach;?>
			
	
	<hr>

	</form>
	<?php }

	
	}else{?>
	<div class="ctn_menu">
		<div class="add_prod">
			<div class="item_form">
					<form action="<?=site_url('cart/insert')?>" method="post" name="addproduct<?=$p->id?>">
						<input type="button" class="moins format_<?=$p->id?>_less" value="-" onclick="less(<?=$p->id?>)">
						<input type="text" name="qty" class="qty" id="item_<?=$p->id?>" value="0" style="width: 20px; text-align: center;" />
						<input type="button" class="plus format_<?=$p->id?>_more" value="+" onclick="more(<?=$p->id?>)"> 
						<input type="hidden" name="url" value="<?=current_url()?>">
						<input type="hidden" class="id_<?=$p->id?>" name="id" value="<?=$p->id?>">
						<input type="hidden" class="price_<?=$p->id?>" name="price" value="<?=$p->product_price?>"> 
						<input type="hidden" class="name_<?=$p->id?>" name="name" value="<?=$p->product_name?>"> 
						<input type="hidden" class="num_<?=$p->id?>" name="product_num" value="<?=$p->product_num?>"> 
						<input type="button" value="ajouter" onclick="add_cart(<?=$p->id?>)">


				</div>
		</div>
		<p class="product_list">
		
		<?=$p->product_num?>
			.
			<?=nbs(2)?>
			<?=$p->product_name?>
			<span class="price"><?=number_format($p->product_price,2,'.','')?> €</span>
			<span class="clear"></span>
			<?php if($p->capture !=null){?>
			<span class="description"><?=$p->capture?> </span>
			<?php }?>

			<?php foreach ($p->attribute_group as $group):?>

				<span> <select name="option[]">
						<option value="">
							Supplément
							<?=$group->attribute_group_name?>
						</option>
						<?php foreach ($group->attribute_product as $product_attribute):?>
						<option value="<?=$product_attribute->id?>">
						<?=$product_attribute->attribute_name?>
						<?=number_format($product_attribute->attribute_price,'2','.','')?>
							€
						</option>
						<?php endforeach;?>
				</select> </span>
				<?php endforeach;?>

		</form>
				</p>
	</div>
	
	<?php }?>
	
	<?php endforeach;?>
	
	<?php }else{?>
	Il y n'a pas de plat dans cette catégorie.
	<?php }?>
	<?php if($this->uri->segment(2) == 3){?>
	<div class="info_supplement">
		<p>Tous les plats (sauf riz sauté et nouilles sautées) sont servis
			avec du riz blanc. Avec un supplément de 1,50 € par plat, vous
			pouvez remplacer le riz blanc par du riz sauté ou des nouilles
			sautées.</p>
		<p>Légumes de base: oignon, chou chinois, champignons, bambou,
			carottes.</p>
		<p>Les légumes peuvent être modifiés sans préavis selon la saison.</p>
		
	</div>
	<?php }?>
</div>
<div class="clear"></div>
</div>
